/* @formatter:off
 * Copyright (c) 2011 Lucas <lucas03093@gmail.com>
 * 
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
/* @formatter:on */

package nu.korkad.daytracker.io;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import nu.korkad.daytracker.settings.Config;

public class Log
{
    public static void toExternal(String data)
    {
        try
        {
            // Create dir on external storage if needed
            File f1 = new File(Config.EXTERNAL_DIR_ROOT);
            f1.mkdirs();
            f1 = null;
            
            // Create file
            FileWriter fw = new FileWriter(Config.LOG_ERROR_FILE, true);
            BufferedWriter out = new BufferedWriter(fw);
            
            // Get date
            DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
            
            // Write data to file
            out.write("\r\n" + df.format(new Date()) + " - " + data);
            
            // Close it
            out.close();
        }
        catch (Exception e)
        {
            System.out.println(e.getMessage());
        }
    }
}
